'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-08-29 17:09:46
LastEditTime: 2025-09-10 09:38:55
'''


class Node:
    def __init__(self, val=0, next=None, random=None):
        self.val = val
        self.next = next
        self.random = random


class Solution:
    def copyRandomList(self, head):
        
        if head is None:
            return None
        
        cur = head
        while cur:
            cur.next = Node(cur.val, cur.next)
            cur = cur.next.next
        
        cur = head
        while cur:
            if cur.random:
                # 复制的链表.random -> 复制的random
                # 可以这样理解，random、random复制
                cur.next.random = cur.random.next

            cur = cur.next.next

        # 遍历交错列表中的新链表节点

        cur = head.next

        while cur.next:
            cur.next = cur.next.next
            # 删除节点需要前进一步
            cur = cur.next

    
        return head.next


    # 暂存


